package com.github.niefy.modules.wx.manage;

import com.github.niefy.common.utils.PageUtils;
import com.github.niefy.common.utils.R;
import com.github.niefy.modules.wx.entity.SubTemplateMsgLog;
import com.github.niefy.modules.wx.service.SubTemplateMsgLogService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import me.chanjar.weixin.mp.api.WxMpService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;


/**
 * 订阅通知消息发送记录
 *
 */
@RestController
@RequestMapping("/manage/subtemplateMsgLog")
@Tag(name = "订阅通知消息发送记录-管理后台")
public class SubTemplateMsgLogManageController {
    @Autowired
    private SubTemplateMsgLogService subTemplateMsgLogService;
    @Autowired
    private WxMpService wxMpService;

    /**
     * 列表
     */
    @GetMapping("/list")
    @RequiresPermissions("wx:subtemplatemsglog:list")
    @Operation(summary = "列表")
    public R list(@CookieValue String appid,@RequestParam Map<String, Object> params) {
        params.put("appid",appid);
        PageUtils page = subTemplateMsgLogService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{logId}")
    @RequiresPermissions("wx:subtemplatemsglog:info")
    @Operation(summary = "详情")
    public R info(@CookieValue String appid,@PathVariable("logId") Integer logId) {
        SubTemplateMsgLog subTemplateMsgLog = subTemplateMsgLogService.getById(logId);

        return R.ok().put("subTemplateMsgLog", subTemplateMsgLog);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    @RequiresPermissions("wx:subtemplatemsglog:save")
    @Operation(summary = "保存")
    public R save(@CookieValue String appid,@RequestBody SubTemplateMsgLog subTemplateMsgLog) {
        subTemplateMsgLogService.save(subTemplateMsgLog);

        return R.ok();
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    @RequiresPermissions("wx:subtemplatemsglog:update")
    @Operation(summary = "修改")
    public R update(@CookieValue String appid,@RequestBody SubTemplateMsgLog subTemplateMsgLog) {
        subTemplateMsgLogService.updateById(subTemplateMsgLog);

        return R.ok();
    }

    /**
     * 删除
     */
    @PostMapping("/delete")
    @RequiresPermissions("wx:subtemplatemsglog:delete")
    @Operation(summary = "删除")
    public R delete(@CookieValue String appid,@RequestBody Integer[] logIds) {
        subTemplateMsgLogService.removeByIds(Arrays.asList(logIds));

        return R.ok();
    }

}
